<template>
  <tr>
    <td>{{ item.id }}</td>
    <td>{{ item.name }}</td>
    <td>{{ item.date }}</td>
    <td>
      <button :disabled="jdgTrue" @click="delBook(item.id)">删除</button>
      <button @click="changeBook(item.id, item.name)">编辑</button>
    </td>
  </tr>
</template>

<script>
import moment from 'moment'

export default {
  props: {
    item: {
      type: Object,
      required: true
    },
    jdgTrue: {
      type: Boolean
    }
  },
  data () {
    return {
      edit: 0
    }
  },
  created () {
    this.changeDate()
  },
  updated () {
    this.changeDate()
  },
  methods: {
    delBook (id) {
      if (this.edit === 0) {
        this.$emit('delBook', id)
      }
    },
    changeBook (id, name) {
      this.edit = 1
      this.$emit('change', [id, name, this.edit])
      // this.edit = 0
    },
    changeDate () {
      this.item.date = moment(this.item.date).format('YYYY-MM-DD')
    }
  }
}
</script>

<style lang='less' scoped>
</style>
